﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MyGeneration.dOOdads;
using MethodIT.Helper;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.ZB
{
    public partial class SubjectKpUmpList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                LoadData();

                //KP_Master m = new KP_Master();
                //m.LoadAll();
                //FunctionSet.FillListControl(ddlApTable, m.DefaultView.Table, "title", "KP_ID");
            }
        }

        private void LoadData()
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");

            vw_SubKpUmp vw = new vw_SubKpUmp();
            vw.Where.SubID.Value = nSubID;
            vw.Where.KpID.Value = nKpID;
            vw.Query.Load();
            dg.DataSource = vw.DefaultView;
            dg.DataBind();

            KP_Master m = new KP_Master();
            m.LoadByPrimaryKey(nKpID);
            if ((m.KP_Category_ID >2) && (m.KP_Category_ID <5))
            {
                lnkAddTextUmp.Enabled = false;
            }

        }

        protected void dg_DeleteCommand(object source, DataGridCommandEventArgs e)
        {
            int ID = HelperDigit.ConvertToInt32(e.Item.Cells[0].Text);

            KP_Subject_Table_Ump u = new KP_Subject_Table_Ump();
            if (u.LoadByPrimaryKey(ID))
            {
                u.MarkAsDeleted();
                u.Save();
                e.Item.Visible = false;
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            HelperURL.Redirect("../Appraisal/SubjectApTable.aspx?ID=" + nSubID.ToString());
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            string URL = string.Format("ChooseUmp.aspx?SubID={0}&KpID={1}&Type=0",nSubID,nKpID);
            HelperURL.Redirect(URL);
        }

        protected void lnkAddTextUmp_Click(object sender, EventArgs e)
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            string URL = string.Format("ChooseUmp.aspx?SubID={0}&KpID={1}&Type=1", nSubID, nKpID);
            HelperURL.Redirect(URL);
        }

        protected void dg_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.Cells[3].Text.Equals("0"))
                {
                    e.Item.Cells[3].Text = "评分专家";
                }
                else
                {
                    e.Item.Cells[3].Text = "指标专家";
                }
            }
        }
    }
}
